// Evol scripts.
// Authors:
//    4144
// Description:
//    test npc1

test,10,10,0	script	npc1#door	NPC_HIDDEN,0,1,{
OnTouch:
    warp "test", 20, 20;
    close;
OnUnTouch:
    doevent "npc1::OnUnTouch";
}

test,10,10,0	script	npc1	NPC_TEST1,3,3,{
    function areatest
    {
        mesn;
        mes "getareausers(\"test\", 7, 7, 13, 13): " + getareausers("test", 7, 7, 13, 13);
        mes "getareausers(7, 7, 13, 13): " + getareausers(7, 7, 13, 13);
        mes "getareausers(\"test\"): " + getareausers("test");
        mes "getareausers(): " + getareausers();
        mes "getareausers(\"test\", 1): " + getareausers("test", 1);
        mes "getareausers(1): " + getareausers(1);
        next;
        return;
    }

L_Start:
    switch (select("show area", "map", "pc", "change npc direction", "quest test", "cart", "items", "chat", "wall", "craft"))
    {
        case 1:
            areatest;
            break;
        case 2:
            while(1)
            {
                .@mask = getmapmask("test");
                mes "current mask: " + str(.@mask);
                switch (select("show sand:show grass:show fog:hide fog:back"))
                {
                    case 1:
                        addremovemapmask "test", 4, 8;
                        break;
                    case 2:
                        addremovemapmask "test", 8, 4;
                        break;
                    case 3:
                        addmapmask "test", 2;
                        break;
                    case 4:
                        removemapmask "test", 2;
                        break;
                    case 5:
                        goto L_Start;
                        break;
                }
            }
            break;

        case 3:
            while(1)
            {
                switch (select("change sex:setmount 0:setmount 1:setmount 2:test command:back"))
                {
                    case 1:
                        changecharsex;
                        break;
                    case 2:
                        setmount 0;
                        break;
                    case 3:
                        setmount 1;
                        break;
                    case 4:
                        setmount 2;
                        break;
                    case 5:
                        clientcommand "emote 1";
                        break;
                    case 6:
                        goto L_Start;
                        break;
                }
            }
            break;
        case 4:
            for (.@f = 0; .@f < 9; .@f ++)
            {
                mes "" + .@f;
                .dir = .@f;
                next;
            }
            break;
        case 5:
            mes "current";
            .@val0 = getq(ShipQuests_Gugli);
            mes "val=" + .@val0;
            setq ShipQuests_Gugli, 10;
            next;
            mes "test 10";
            next;
            .@val = getq(ShipQuests_Gugli);
            mes "val=" + .@val;
            setq ShipQuests_Gugli, .@val0;
            next;
            break;
        case 6:
            while(1)
            {
                switch (select("add cart:remove cart:back"))
                {
                    case 1:
                        setcart 1;
                        break;
                    case 2:
                        setcart 0;
                        break;
                    case 3:
                        goto L_Start;
                        break;
                }
            }
            break;
        case 7:
            while(1)
            {
                switch (select("refine", "rent", "bound", "named", "cards", "back"))
                {
                    case 1:
                        .@item = -1;
                        while(1)
                        {
                            switch (select("set item", "refine +1", "refine -1", "refine fail", "back"))
                            {
                                case 1:
                                    .@item = requestitemindex();
                                    mes "Item index selected: " + str(.@item);
                                    break;
                                case 2:
                                    successrefindex .@item, 1;
                                    break;
                                case 3:
                                    downrefindex .@item, 1;
                                    break;
                                case 4:
                                    failedrefindex .@item;
                                    break;
                                case 5:
                                    goto L_Start;
                                    break;
                            }
                        }
                        break;
                    case 2:
                        while(1)
                        {
                            switch (select("rent vneck for 10 seconds",
                                "rent vneck for 30 seconds",
                                "rent vneck for 1 minute",
                                "rent vneck for 5 minutes",
                                "back"))
                            {
                                case 1:
                                    rentitem 1301, 10;
                                    break;
                                case 2:
                                    rentitem 1301, 30;
                                    break;
                                case 3:
                                    rentitem 1301, 60;
                                    break;
                                case 4:
                                    rentitem 1301, 300;
                                    break;
                                case 5:
                                    goto L_Start;
                                    break;
                            }
                        }
                        break;
                    case 3:
                        while(1)
                        {
                            switch (select("get bound vneck",
                                "back"))
                            {
                                case 1:
                                    getitembound2 1301, 1, 1, 0, 0, 0, 0, 0, 0, 1;
                                    break;
                                case 2:
                                    goto L_Start;
                                    break;
                            }
                        }
                        break;
                    case 4:
                        while(1)
                        {
                            switch (select("get named vneck",
                                "back"))
                            {
                                case 1:
                                    getnameditem 1301, "4144";
                                    break;
                                case 2:
                                    goto L_Start;
                                    break;
                            }
                        }
                        break;
                    case 5:
                        .@item = -1;
                        while(1)
                        {
                            switch (select("set item",
                                "remove cards success",
                                "fail, remove both",
                                "fail, remove card",
                                "fail, remove item",
                                "fail, safe",
                                "back"))
                            {
                                case 1:
                                    .@item = requestitemindex();
                                    mes "Item index selected: " + str(.@item);
                                    break;
                                case 2:
                                    successremovecardsindex .@item;
                                    break;
                                case 3:
                                    failedremovecardsindex .@item, 0;
                                    break;
                                case 4:
                                    failedremovecardsindex .@item, 1;
                                    break;
                                case 5:
                                    failedremovecardsindex .@item, 2;
                                    break;
                                case 6:
                                    failedremovecardsindex .@item, 3;
                                    break;
                                case 7:
                                    goto L_Start;
                                    break;
                            }
                        }
                        break;
                    case 6:
                        goto L_Start;
                        break;
                }
            }
            break;
        case 8:
            chatjoin .chat;
            close;
        case 9:
            while(1)
            {
                switch (select("set wall 1:set wall 2:set wall 3:delete wall 1:delete wall 2:delete wall 3:back"))
                {
                    case 1:
                        setcells "test", 14, 11, 17, 11, 3, "wall1";
                        break;
                    case 2:
                        setcells "test", 14, 7, 21, 8, 1, "wall2";
                        break;
                    case 3:
                        setcells "test", 13, 15, 13, 21, 3, "wall3";
                        break;
                    case 4:
                        delcells "wall1";
                        break;
                    case 5:
                        delcells "wall2";
                        break;
                    case 6:
                        delcells "wall3";
                        break;
                    case 7:
                        goto L_Start;
                        break;
                }
            }
            break;
        case 10:
            while(1)
            {
                switch (select("technical:normal:back"))
                {
                    case 1:
                        setskin "test2";
                        .@var$ = requestcraft(9);
                        mes .@var$;
                        .@craft = initcraft(.@var$);
                        mes "craft id: " + str(.@craft);
                        mes "is craft valid: " + validatecraft(.@craft);
                        .@id = getcraftslotid(.@craft, 0);
                        .@amount = getcraftslotamount(.@craft, 0);
                        mes "first item id: " + .@id;
                        mes "first item name: " + getitemlink(.@id);
                        mes "first item amount: " + .@amount;

                        .@id = getcraftslotid(.@craft, 1);
                        .@amount = getcraftslotamount(.@craft, 1);
                        mes "second item id: " + .@id;
                        mes "second item name: " + getitemlink(.@id);
                        mes "second item amount: " + .@amount;
//                        dumpcraft .@craft;
                        .@entry = findcraftentry(.@craft, 0);
                        mes "found craft entry: " + .@entry;
                        if (.@entry < 0)
                        {
                            mes "no craft recipe found";
                        }
                        else
                        {
                            mes "use craft";
                            usecraft .@craft;
                            mes "return code: " + getcraftcode(.@entry);
                        }
                        deletecraft .@craft;
                        setskin "";
                        break;
                    case 2:
                        mes "put items what you want to craft";
                        setskin "test2";
                        .@var$ = requestcraft(9);
                        setskin "";
                        .@craft = initcraft(.@var$);
                        if (.@craft < 0)
                        {
                            mes "Craft error.";
                            goto L_Start;
                        }
                        mes "lets see what you can get...";
                        next;
                        if (!validatecraft(.@craft))
                        {
                            mes "inventory was changed.";
                            goto L_Start;
                        }
                        .@entry = findcraftentry(.@craft, 0);
                        if (.@entry < 0)
                        {
                            mes "no craft recipe found";
                        }
                        else
                        {
                            mes "found recipe";
                            usecraft .@craft;
                            mes "return code: " + getcraftcode(.@entry);
                        }
                        deletecraft .@craft;
                        break;
                    case 3:
                        goto L_Start;
                        break;
                }
            }
            break;
    }

    close;

OnTouch:
    doorTouch;

OnUnTouch:
    doorUnTouch;

OnTimer340:
    doorTimer;

OnInit:
    .sex = G_MALE;
    .distance = 5;
    .alwaysVisible = true;
    waitingroom "test room", 2, "npc1::OnReadyCheck", 1;
    end;

OnWhisperGlobal:
    mes "cmd: " + @whispervar0$;
    close;

OnSkillInvoke:
    skillInvoke[@skillId] = skillInvoke[@skillId] + 1;
    end;

OnReadyCheck:
    debugmes "OnReadyCheck";
    $@bgid1 = waitingroom2bg("testbg", 10, 10, "bgnpc1::OnLogout","bgnpc1:OnDie");
    debugmes "bgid=" + str($@bgid1);
    setbgteam $@bgid1, 1;
    bg_warp $@bgid1, "testbg", 10, 10;
}
